package com.zaofan.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.zaofan.bean.UserImage;
import com.zaofan.constant.UrlConstant;
import com.zaofan.dao.base.DaoSupportImpl;

public class UserImageDao extends DaoSupportImpl<UserImage> {

	public List<UserImage> findByUserId(String begin, String end, Integer userId) {
		try {
			String sql = "select id,userId,concat('" + UrlConstant.HOST_URL
					+ "',image) as image ,type,dynamicId,replyId from userimage where userId = " + userId
					+ " order by id desc limit " + begin + "," + end;
			System.err.println(sql);
			QueryRunner runner = new QueryRunner(getDataSource());
			return runner.query(sql, new BeanListHandler<>(UserImage.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

}
